<?php
class AuctionHistoryList extends CRedisModel{
	const AUCTION_HISTORY_PRE='bidHistory';
	const AUCTION_HISTORY_LIMIT=10;
	protected $_historyKey;
	
	public function setHistoryKey($key){
		$this->_historyKey=self::AUCTION_HISTORY_PRE.':'.$key;
		return $this;
	}
	
	public function addItem($score,$value){
		$this->redis()->zAdd($this->_historyKey,$score,$value);	
		return $this;	
	}
	
	public function delItem($value){
		$this->redis()->zRem($this->_historyKey,$value);
		return $this;
	}
	
	public function getHistoryList(){
		$historyList=$this->redis()->zRevRange($this->_historyKey,0,self::AUCTION_HISTORY_LIMIT);
		$result=array();
		if (!empty($historyList)) {
			foreach ($historyList as $score=>$history){
				$data=json_decode($history,true);
				if(!empty($data)){
					$result[]=$data;
				}
			}
		}
		return $result;
	}
	
	public function delItems($pk){
		$this->setHistoryKey($pk);
		return $this->redis()->zRemRangeByRank($this->_historyKey,0,-1);
	}
}